package com.sky.mapper;

import com.sky.annotation.AutoFill;
import com.sky.dto.SetmealDTO;
import com.sky.entity.Setmeal;
import com.sky.enumeration.OperationType;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Options;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface SetmealMapper {

    /**
     * 根据分类id查询套餐的数量
     * @param id
     * @return
     */
    @Select("select count(id) from setmeal where category_id = #{categoryId}")
    Integer countByCategoryId(Long id);



    @Insert("insert into setmeal(category_id, name, price,status, description, image, create_time, update_time, create_user, update_user)" +
            "values (#{categoryId},#{name},#{price},#{status},#{description},#{image},#{createTime},#{updateTime},#{createUser},#{updateUser})")
    @AutoFill(OperationType.INSERT)
    @Options(useGeneratedKeys = true,keyProperty = "id")
    void insert(Setmeal setmeal);

    /**
     * 批量删除套餐基本信息
     * @param ids
     */
    void deleteBatch(List<Long> ids);

    /**
     * 拖过ids 查找套餐信息
     * @param ids
     * @return
     */
    List<Setmeal> queryByIds(List<Long> ids);

    /**
     * 通过id查找套餐信息
     * @param id
     * @return
     */
    Setmeal queryById(Long id);

    /**
     * 套餐信息更新
     * @param setmeal
     */
    @AutoFill(OperationType.UPDATE)
    void update(Setmeal setmeal);

    /**
     * 通过分类id 查找套餐
     * @param categoryId
     * @return
     */
    List<Setmeal> queryByCategoryId(Long categoryId);

    /**
     * 通过套餐id 查询套餐
     * @param id
     * @return
     */
    @Select("select *from setmeal where id = #{id}")
    Setmeal selectById(Long id);

    /**
     *  根据订单状态查询套餐数量
     * @param status 1启用 0停售
     * @return
     */
    Integer countByStatus(Integer status);
}
